package dbops


import(
	_ "github.com/go-sql-driver/mysql" //匿名导入
)

//从video_del_rec表获取要删除的视频ID
//用于executer执行删除

//获取需要删除的视频ID
func ReadVideoDeletionRecord(count int) ([]string, error) {
	stmtOut, err := dbConn.Prepare("SELECT video_id FROM video_del_rec LIMIT ?")
	defer stmtOut.Close()
	if err != nil {
		return nil, err
	}
	rows, err := stmtOut.Query(count)
	if err != nil {
		return nil, err
	}
	var ids []string
	for rows.Next() {
		var video_id string
		err := rows.Scan(&video_id)
		if err != nil {
			return ids, err
		}
		ids = append(ids, video_id)
	}

	return ids, nil
}

//把待删除的视频ID删除
func DelVideoDeletionRecord(vid string) error {
	stmtDel, err := dbConn.Prepare("DELETE FROM video_del_rec WHERE video_id=?")
	defer stmtDel.Close()
	if err != nil {
		return err
	}
	_, err = stmtDel.Exec(vid)
	return err
}
